import $http from "@/services";
export default {
    state: {
        assesLists: [],
        assesTotal: 0,
        assesDetail: null,
        assesSearch: {
            page: 1,
            size: 5,
            queryData: {}
        }
    },
    // 赋值
    reducers: {
        setAssessLists(state, { payload }) {
            return { ...state, assesLists: payload }
        },
        setAssessTotal(state, { payload }) {
            return { ...state, assesTotal: payload }

        },
        setAssessDetail(state, { payload }) {
            return { ...state, assesDetail: payload }
        },
        setAssessSearch(state, { payload }) {
            return { ...state, assesSearch: { ...state.assesSearch, ...payload } };
        }
    },
    effects: {
        // 初始化数据，获取数据
        *initAssesContent({ payload }, { put, call, select }) {
            // 重新处理请求关系
            yield put({
                type: "setAssessSearch",
                payload
            })
            const { assesSearch } = yield select(state => state.assessment);
            //请求数据
            const { data, msg, total } = yield call($http.getAssessmentList, assesSearch);
            console.log(data, msg, total)
            yield put({
                type: "setAssessLists",
                payload: data.list
            })
            console.log(data)
            yield put({
                type: "setAssessTotal",
                payload: total
            })

        },
        // 重新获取绩效详情
        *getDetailAsses({ payload }, { put, call }) {
            const { data } = yield call($http.getAssessmentDetail, payload);
            if (data) {
                yield put({
                    type: "setAssessDetail",
                    payload: data
                })
                yield put({
                    type: "common/setIsShowDetail",
                    payload: true
                });
            }

        }
    }
}